from flask import jsonify


def success_api(msg: str = "成功", data={}):
    """ 成功响应 默认值“成功” """
    return jsonify(success=True, code=200, msg=msg, data=data)


def fail_api(msg: str = "失败", code=500):
    """ 失败响应 默认值“失败” """
    return jsonify(success=False, code=code, msg=msg)


def table_api(msg: str = "", total=0, data=None):
    """ 动态表格渲染响应 """
    res = {
        'msg': msg,
        'code': 0,
        'rows': data,
        'total': total
    }
    return jsonify(res)
